import { UploadOutlined } from '@ant-design/icons';
import { useModel } from '@umijs/max';
import type { UploadProps } from 'antd';
import { Button, Upload, message } from 'antd';
import styles from './index.less';

const UploadPage = () => {
  const { setFile_path } = useModel('Resume.resumeModel');

  const uploadProps: UploadProps = {
    name: 'file',
    action: API_REQUEST_URL + '/upload',
    maxCount: 1,
    onChange(info: any) {
      if (info.file.status === 'done') {
        message.success(`${info.file.name} 上传成功`);
        if (info.file.response.code === 1) {
          setFile_path(info.file.response.message);
        }
      } else if (info.file.status === 'error') {
        message.error(`${info.file.name} 上传失败，请重试`);
        setFile_path('');
      }
    },
    onRemove: () => {
      setFile_path('');
    },
  };

  return (
    <div className={styles.box}>
      <Upload {...uploadProps}>
        <Button icon={<UploadOutlined />}>上传简历</Button>
      </Upload>
    </div>
  );
};

export default UploadPage;
